package com.um.jdy.platform.device.controller;

import com.um.jdy.common.device.entity.dto.CodeDTO;
import com.um.jdy.common.device.entity.po.Code;
import com.um.jdy.common.device.entity.vo.CodeVO;
import com.um.jdy.common.device.service.CodeService;
import com.um.jdy.platform.device.entity.dto.CodeExportDTO;
import com.um.jdy.platform.device.entity.dto.CodePageDTO;
import com.um.jdy.platform.device.entity.dto.CodeParams;
import com.um.jdy.platform.device.entity.dto.CodePortExportDTO;
import com.um.jdy.platform.device.manger.PileCodeManager;
import com.um.jdy.platform.station.entity.dto.FeePageDTO;
import com.um.springboot.starter.annotation.ApiPermission;
import com.um.springboot.starter.annotation.TokenRequired;
import com.um.springboot.starter.entity.Page;
import com.um.springboot.starter.orm.controller.BaseCMSController;
import com.um.springboot.starter.orm.controller.BasePlusController;
import com.um.springboot.starter.orm.entity.Response;
import com.um.springboot.starter.orm.params.ExportParams;
import com.um.springboot.starter.orm.params.ListDTO;
import com.um.springboot.starter.orm.params.PageParams;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 控制器：充电桩二维码
 */
@RestController
@RequestMapping("/api/v1/cms/device/pile_code")
@Api(tags = "设备管理", description = "充电桩二维码")
@ApiPermission("pile_code")
@TokenRequired
@Validated
public class PileCodeController extends BasePlusController<PileCodeManager, CodeService, Code, CodeDTO, CodeVO,CodePageDTO, ListDTO> {

    /**
     * 查询分页
     *
     * @param params
     * @return
     */
    @ApiPermission("page")
    @ApiOperation("分页桩二维码")
    @PostMapping("/code_page")
    public Response<Page<Code>> getFeePage(@RequestBody CodePageDTO params) {
        return manager.page(params);
    }

    /**
     * 生成设备码
     *
     * @param params
     * @return
     */
    @ApiPermission("generate")
    @ApiOperation("生成设备码")
    @PostMapping("/generate_code")
    public Response generateCode(@RequestBody CodeParams params) {
        return manager.generateCode(params.getPrefixName(), params.getNum());
    }

    /**
     * 导出二维码Excel
     *
     * @param params
     * @return
     */
    @ApiPermission("export")
    @ApiOperation("导出二维码Excel")
    @PostMapping("/export_code_page")
    public Response exportCodePage(@RequestBody CodeExportDTO params){
        ExportParams exportParams = params.toExportParams(new String[]{"name","code"},new String[]{"name","code"});
        return manager.exportCodePage(exportParams);
    }


    /**
     * 导出二维码
     *
     * @param params
     * @return
     */
    @ApiPermission("export_qrcode")
    @ApiOperation("导出二维码")
    @PostMapping("/export_qrcode")
    public Response exportQRCode(@RequestBody CodeExportDTO params) {
        ExportParams exportParams = params.toExportParams(new String[]{"name","code"},new String[]{"name","code"});
        return manager.exportQrcode(exportParams);
    }

    /**
     * 导出插座二维码
     *
     * @param params
     * @return
     */
    @ApiPermission("export_socket")
    @ApiOperation("导出插座二维码")
    @PostMapping("/export_socket_qrcode")
    public Response exportSocketQrcode(@RequestBody CodePortExportDTO params) {
        ExportParams exportParams = params.toExportParams(new String[]{"name","code"},new String[]{"name","code"});

        return  Response.success(manager.exportSocketQrcode(exportParams,params.getPortNum()));
    }
}
